package _8GuoLvQi.impl;

import _8GuoLvQi.Criteria;
import _8GuoLvQi.Person;

import java.util.List;

/**
 * @OrCriteria: 不都符合
 * @author: ZBoHang
 * @time: 2021/9/7 15:42
 */
public class OrCriteria implements Criteria {

    private Criteria criteria;
    private Criteria otherCriteria;

    public OrCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    @Override
    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> firstCriteriaItems = criteria.meetCriteria(persons);
        List<Person> otherCriteriaItems = otherCriteria.meetCriteria(persons);
        for (Person firstCriteriaItem : firstCriteriaItems) {
            if (!otherCriteriaItems.contains(firstCriteriaItem)) {
                otherCriteriaItems.add(firstCriteriaItem);
            }
        }
        return otherCriteriaItems;
    }
}
